#region File Description
//-----------------------------------------------------------------------------
// MainMenuScreen.cs
//
// Microsoft XNA Community Game Platform
// Copyright (C) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
#endregion

#region Using Statements
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Net;
#endregion

namespace TankWars
{
    /// <summary>
    /// The main menu screen is the first thing displayed when the game starts up.
    /// </summary>
    class MainMenuScreen : MenuScreen
    {
        #region fields

        const int maxLocalGamers = 4;   // Must change this in "NetworkSelectionScreen.cs" too

        bool signedIn = false;

        #endregion

        #region Initialization


        /// <summary>
        /// Constructor fills in the menu contents.
        /// </summary>
        public MainMenuScreen() : base("RAGADE'S ROLLIN' CANNONS")
        {
            // Create our menu entries.
            //MenuEntry localGameMenuEntry = new MenuEntry("Local Game");
            MenuEntry networkGameMenuEntry = new MenuEntry("Network Game");
            MenuEntry optionsMenuEntry = new MenuEntry("Options");
            MenuEntry exitMenuEntry = new MenuEntry("Exit");

            // Hook up menu event handlers.
            //localGameMenuEntry.Selected += LocalGameMenuEntrySelected;
            networkGameMenuEntry.Selected += NetworkGameMenuEntrySelected;
            optionsMenuEntry.Selected += OptionsMenuEntrySelected;
            exitMenuEntry.Selected += OnCancel;

            // Add entries to the menu.
            //MenuEntries.Add(localGameMenuEntry);
            MenuEntries.Add(networkGameMenuEntry);
            MenuEntries.Add(optionsMenuEntry);
            MenuEntries.Add(exitMenuEntry);
        }


        #endregion

        #region Handle Input

        /*
        /// <summary>
        /// Event handler for when the Local Game menu entry is selected.
        /// </summary>
        void LocalGameMenuEntrySelected(object sender, EventArgs e)
        {
            LoadingScreen.Load(ScreenManager, true, new LocalGameplayScreen());
        }
         */ 

        /// <summary>
        /// Event handler for when the Network Game menu entry is selected.
        /// </summary>
        void NetworkGameMenuEntrySelected(object sender, EventArgs e)
        {
            // Check to see if the user is signed into the network, and if not,
            //  bring up the login screen.
            if (!signedIn)
            {
                signedIn = true;
                // If there are no profiles signed in, we cannot proceed.
                // Show the Guide so the user can sign in.
                Guide.ShowSignIn(maxLocalGamers, false);
            }            

            // After sign-in is complete, load the screen for network connection selection
            ScreenManager.AddScreen(new NetworkSelectionScreen(NetworkSessionType.SystemLink));
        }

        /// <summary>
        /// Event handler for when the Options menu entry is selected.
        /// </summary>
        void OptionsMenuEntrySelected(object sender, EventArgs e)
        {
            ScreenManager.AddScreen(new OptionsMenuScreen());
        }


        /// <summary>
        /// When the user cancels the main menu, ask if they want to exit the sample.
        /// </summary>
        protected override void OnCancel()
        {
            const string message = "Are you sure you want to exit the game?";

            MessageBoxScreen confirmExitMessageBox = new MessageBoxScreen(message);

            confirmExitMessageBox.Accepted += ConfirmExitMessageBoxAccepted;

            ScreenManager.AddScreen(confirmExitMessageBox);
        }


        /// <summary>
        /// Event handler for when the user selects ok on the "are you sure
        /// you want to exit" message box.
        /// </summary>
        void ConfirmExitMessageBoxAccepted(object sender, EventArgs e)
        {
            ScreenManager.Game.Exit();
        }


        #endregion
    }
}
